package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.ShopCar;
import cn.wolfcode.shop.service.IShopCarService;
import cn.wolfcode.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/shopCars")
public class ShopCarController {

    @Reference
    private IShopCarService shopCarService;


    /**
     * 注解@requestHeader 通过它即可将请求头中的属性值绑定到处理方法的形参中
     * @param token 唯一的token
     * @param productSkuId  选择加入购物车的商品id
     * @param number 购物车商品数量
     * @return
     */
    @PostMapping
    public JSONResultVo addShopCar(@RequestHeader("userToken") String token, Long productSkuId, BigDecimal number) {
        JSONResultVo vo = new JSONResultVo();

        ShopCar shopCar = shopCarService.addShopCar(token, productSkuId, number);
        vo.setResult(shopCar);
        return vo;
    }

}
